﻿#region
/*******************************************************************************
** File Name:		    RightsService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using Phoenix.Service.Contracts;
using Phoenix.Service.Model;
using Phoenix.IBatisRepository;
using Phoenix.Respository;
using System.Data;
using Phoenix.Entity;

namespace Phoenix.Service
{
    public class RightsService : IRightsService
    {
		 IRights rights = new RightsRepository();
		 
		 #region  Auto Generation

         public void AddRights(RightsModel model)
        {
			ERights entity = ConvertModelToEntity(model);
			
             rights.AddRights(entity);
        }

		public void UpdateByRightID (RightsModel model)
		{
			ERights entity = ConvertModelToEntity(model);

            rights.UpdateByRightID(entity);

		}

		public void DeleteByRightID (System.Int32 rightID)
		{
		
            rights.DeleteByRightID(rightID);

		}
		 
        public RightsModel GetByRightID (System.Int32 rightID)
        {
        
			ERights entity = rights.GetByRightID(rightID);
			
            RightsModel model = ConvertEntityToModel(entity);


            return model;
        }
        
		public RightsModel ConvertEntityToModel(ERights entity)
		{
			if (entity == null)
            {
                return null;
            }
			RightsModel model = new RightsModel();
                        model.RightID = entity.RightID;
                        model.RightName = entity.RightName;
                        model.RightTypeID = entity.RightTypeID;
                        model.RightDisplayName = entity.RightDisplayName;
                        model.RightMemo = entity.RightMemo;
                        model.SystemFlag = entity.SystemFlag;
                        model.CreateTime = entity.CreateTime;
                        model.CreateUser = entity.CreateUser;
                        model.UpdateTime = entity.UpdateTime;
                        model.UpdateUser = entity.UpdateUser;
                        return model;
		}
		
		public ERights ConvertModelToEntity(RightsModel model)
		{
			if (model == null)
            {
                return null;
            }
			ERights entity = new ERights();
                        entity.RightID = model.RightID;
                        entity.RightName = model.RightName;
                        entity.RightTypeID = model.RightTypeID;
                        entity.RightDisplayName = model.RightDisplayName;
                        entity.RightMemo = model.RightMemo;
                        entity.SystemFlag = model.SystemFlag;
                        entity.CreateTime = model.CreateTime;
                        entity.CreateUser = model.CreateUser;
                        entity.UpdateTime = model.UpdateTime;
                        entity.UpdateUser = model.UpdateUser;
                        return entity;
		}
		
		#endregion
        public IList<RightsModel> GetAll()
        {
            IList<ERights> entityList = rights.GetAll();

            if (entityList == null)
                return null;
            IList<RightsModel> modelList = new List<RightsModel>();

            foreach (var item in entityList)
            {
                RightsModel model = ConvertEntityToModel(item);
                modelList.Add(model);
            }
            return modelList;
        }

		public IList<RightsModel> GetByRightsTypeID(int rightsTypeID)
		{
			IList<ERights> entityList = rights.GetByRightTypeID(rightsTypeID);

			if (entityList == null)
				return null;
			IList<RightsModel> modelList = new List<RightsModel>();

			foreach (var item in entityList)
			{
				RightsModel model = ConvertEntityToModel(item);
				modelList.Add(model);
			}
			return modelList;
		}
    }
}